<template>
  <div style="margin: 20px">
    <el-card class="box-card">
      <h1>添加公告</h1>
      <el-form :model="addForm" :rules="rules" ref="addForm" label-width="100px" class="demo-ruleForm">
        <el-form-item label="公告标题" prop="title">
          <el-input v-model="addForm.title"></el-input>
        </el-form-item>
        <el-form-item label="公告内容" prop="content">
          <el-input type="textarea" v-model="addForm.content"></el-input>
        </el-form-item>
        <el-form-item label="发布人" prop="publisher">
          <el-input v-model="addForm.publisher"></el-input>
<!--          <el-select v-model="addForm.publisher" placeholder="请选择">-->
<!--            <el-option-->
<!--              v-for="item in options"-->
<!--              :key="item.value"-->
<!--              :label="item.label"-->
<!--              :value="item.value">-->
<!--            </el-option>-->
<!--          </el-select>-->
        </el-form-item>
        <el-form-item label="发布时间" prop="publishTime">
          <div class="block">
            <el-date-picker
              v-model="addForm.publishTime"
              type="date"
              placeholder="选择日期">
            </el-date-picker>
          </div>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="addFood">确定添加</el-button>
          <el-button @click="resetForm">重置</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
export default {
  name: "addNotice",
  data(){
    return{
      // user: JSON.parse(window.sessionStorage.getItem("user"),
      addForm: {},
      rules: {
        title:[{ required: true, message: '请输入公告标题', trigger: 'blur' }],
        content:[{ required: true, message: '请输入公内容', trigger: 'blur' }],
        publisher:[{ required: true, message: '请输入发布人', trigger: 'blur' }],
        publishTime:[{ required: true, message: '请输入发布时间', trigger: 'blur' }],
      },
      options: [{value: 1, label: "清蒸"},{value: 2, label: "水煮"},{value: 3, label: "爆炒"},{value: 4, label: "甜品"}],
    }
  },
  methods:{
    handleChange(file, fileList){
      if (fileList.length > 1) {
        fileList.splice(0, 1);
      }
      // console.info(file)
      // this.imageUrl = URL.createObjectURL(file.raw);
      // console.info(this.imageUrl)
    },
    handleSuccess(response){
      this.$message.success("上传文件成功！")
      console.info(response.data)
      let path = response.data
      this.addForm.savepath = path
    },
    addFood(){
      this.$refs.addForm.validate((valid) => {
        if (valid) {
          this.axios.post("http://localhost:8080/notice/add", this.addForm).then(res => {
            if (res.data.code == 200) {
              this.$message.success("添加成功！")
              this.$refs.addForm.resetFields();
              this.addForm = {}
              this.$refs.upload.clearFiles()
            }
          })
        }else {
          this.$message.error("请完善信息")
        }
      })

    },
    resetForm(formName) {
      this.$refs.addForm.resetFields();
    }
  }
}
</script>

<style scoped>

</style>
